"""
model name : 目标跟踪
file       : 1_YOLO数据标签可视化.py
information:
    author : OuYang
    time   : 2025/7/19
"""

import cv2
from utils.opencv import show_image

image_path = "../data/0001.jpg"
label_path = "../data/0001.txt"

# 读取图片
image_src = cv2.imread(image_path)
# show_image(image_src)

# 读取标签数据
labels = []
with open(label_path, "r") as f:

    for line in f.readlines():
        label = line.strip().split()

        x = float(label[1])
        y = float(label[2])
        w = float(label[3])
        h = float(label[4])
        labels.append([x, y, w, h])

# 获取图片大小
width, height = image_src.shape[1], image_src.shape[0]

# 绘制矩形框
for label in labels:
    x, y, w, h = label

    x1 = int((x - w / 2) * width)
    y1 = int((y - h / 2) * height)
    x2 = int((x + w / 2) * width)
    y2 = int((y + h / 2) * height)

    cv2.rectangle(image_src, (x1, y1), (x2, y2), (0, 255, 0))

show_image(image_src)
